<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@page import="org.springframework.web.context.WebApplicationContext"%>
<%@page import="org.springframework.web.context.support.WebApplicationContextUtils"%>
<%@page import="db.SupplierDAO"%>
<%@page import="db.Supplier"%>
<%@ include file="/jsp/common/utility/logined.jsp" %>
<%
	request.setCharacterEncoding("utf-8");
	
	WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
	SupplierDAO supplierDao = (SupplierDAO)ctx.getBean("SupplierDAO");
	
	Integer teamId = (Integer)session.getAttribute("tid");
	
	String name = request.getParameter("name");
	String person = request.getParameter("person");
	String phone = request.getParameter("phone");
	String remark = request.getParameter("remark");
	
	try{
		Supplier supplier = new Supplier();
		supplier.setDate(new Date());
		supplier.setIsDelete(0);
		supplier.setName(name);
		supplier.setPerson(person);
		supplier.setPhone(phone);
		supplier.setTeamId(teamId);
		if(remark == null) remark = "";
		supplier.setRemark(remark);
		
		supplierDao.save(supplier);
		
		request.setAttribute("info","success");
		
		pageContext.forward("/vm/supinfo/add_supinfo.vm");
	}catch(Exception e){
		request.setAttribute("info","error");
		
		pageContext.forward("/vm/supinfo/add_supinfo.vm");
	}
%>